'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _database = require('../config/database');

var _database2 = _interopRequireDefault(_database);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

const getRebateConfig = (() => {
  var _ref = _asyncToGenerator(function* (rebateId) {
    let topLimit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
    let buttonLimit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4999;

    let recordInfo = null;
    let sql = `SELECT * FROM t_rebate_quota
    WHERE id = ${rebateId} AND ${buttonLimit} >= botton_limit  AND ${topLimit} < top_limit`;
    try {
      // console.log(sql)
      recordInfo = yield _database2.default.query(sql);
    } catch (err) {
      console.log(`search yp_order_record ${err}`);
    }
    return recordInfo[0];
  });

  return function getRebateConfig(_x) {
    return _ref.apply(this, arguments);
  };
})();

exports.default = {
  getRebateConfig
};